package com.leige.utils.setting;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

/**
 * 全局的参数配置的类
 * @author Administrator
 *
 */
@Component
public final class Const implements ApplicationContextAware {
	public static final Log logger = LogFactory.getLog(Const.class);
	
	/**
	 * spring 上下文
	 */
	public static ApplicationContext context;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { context=applicationContext;	}
	
	/**
	 * 当前系统时间和数据库时间的毫秒差
	 */
	private static Long sys_sql_data_gap=0L;
	
	public static void setSys_sql_data_gap(long db_timestamp) {
		Const.sys_sql_data_gap = db_timestamp-System.currentTimeMillis();
	}
	
	public final static long getSysTimestamp() {
		// TODO Auto-generated method stub
		return System.currentTimeMillis()+sys_sql_data_gap;
	}
	public final static Date getSysDate() {
		// TODO Auto-generated method stub
		return new Date(getSysTimestamp());
	}

}
